#include <iostream>
#include <string>
#include <unordered_set>
#include <cmath>
#include <vector>

using namespace std;

struct Doc {
    string checksum;
    char type;
    string id;
    int x;
    int y;
};

struct Match {
    string cid;
    string sid;
    int cx;
    int cy;
    int sx;
    int sy;

    double getDist() {
        double dist = sqrt(pow(cy - sy, 2) + pow(cx - sx, 2));
        return double(int((dist + 0.005) * 100)) / 100;
    }
};

int compare(Match a, Match b) {
    return a.getDist() < b.getDist();
}

int main() {
    int N;
    cin >> N;
    Doc *docs = new Doc[2 * N];
    unordered_set<string> s;
    for (int i = 0; i < 2 * N; ++i) {
        cin >> docs[i].checksum >> docs[i].type >> docs[i].id >> docs[i].x >> docs[i].y;
        s.insert(docs[i].checksum);
    }

    vector<Match> vec;
    for (const string &c: s) {
        Match match;
        for (int i = 0; i < 2 * N; ++i) {
            if (docs[i].checksum == c && docs[i].type == 'C') {
                match.cid = docs[i].id;
                match.cx = docs[i].x;
                match.cy = docs[i].y;
            }
            if (docs[i].checksum == c && docs[i].type == 'S') {
                match.sid = docs[i].id;
                match.sx = docs[i].x;
                match.sy = docs[i].y;
            }
        }
        vec.push_back(match);
    }

    sort(vec.begin(), vec.end(), compare);

    for (auto match: vec) {
        printf("%s %s %.2f\n", match.cid.c_str(), match.sid.c_str(), match.getDist());
    }
}